<?php
@header('Content-type: text/html;charset=UTF-8');
require_once('ly_check.php');
?>
<?php
if ($_POST["Submit"]) {
    $companyId = str_replace(' ','',$_POST["companyId"]);
    $companyName = str_replace(' ','',$_POST["companyName"]);
    $companyPwd = md5("888888");
    $memo = str_replace(' ','',$_POST["memo"]);
    $sql = "select * from company where companyid='$companyId'";
    $rs = mysql_query($sql);
    if (mysql_num_rows($rs) == 1) {
        echo "<script language=javascript>alert('企业编号已存在！');history.back();</script>";

    } else {
        $sql = "insert into company (companyid,companyname)" .
            " values ('$companyId','$companyName')";
        mysql_query($sql);
        $sql = "insert into admin (username,password,userId,companyname,flag)" .
        		" values ('$companyId','$companyPwd','$companyId','$companyName',2)";
        mysql_query($sql);
        echo "<script language=javascript>alert('添加成功！');window.location='index.php?pageno=$pageno'</script>";
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>企业添加</title>
    <link rel="stylesheet" href="../images/css.css" type="text/css"/>
    <script type="text/javascript">
        function check() {
            var companyId = document.getElementById("companyId");
            var companyName = document.getElementById("companyName");
            var serviceStationPwd = document.getElementById("serviceStationPwd");
            if (trim(companyId.value) == null || trim(companyId.value) == "") {
                alert("请输入企业编号");
                companyId.focus();
                return false;
            }
            if (trim(companyName.value) == null || trim(companyName.value) == "") {
                alert("请输入企业名称");
                companyName.focus();
                return false;
            }
            if (trim(serviceStationPwd.value) == null || trim(serviceStationPwd.value) == "") {
                alert("请输入企业密码");
                serviceStationPwd.focus();
                return false;
            }

            return true;
        }
        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
</head>
<form id="form1" name="form1" method="post" action="" onsubmit="return check();">
    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" bordercolor="#000000"
           bgcolor="#cccccc">
        <tr>
            <th colspan="2" bgcolor="#FFFFFF">添加企业</th>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">企业编号:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="companyId"
                                                                   id="companyId"/>*
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">企业名称:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="companyName"
                                                                   id="companyName"/>*
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input name="Submit" type="submit" class="button" value="保存"/>
                &nbsp;
                <input name="Submit2" type="reset" class="button" value="重置"/></td>
        </tr>
    </table>
</form>
</body>
</html>